/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 11:22:47 AM
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
import org.jdom.Element;

// Referenced classes of package dk.brics.dsd:
//            Declaration, AttributeDeclaration, Context, Validator,
//            Schema

class RequiredDeclaration extends Declaration
{

    RequiredDeclaration(Element element, Schema schema)
    {
        contents = parseList(element, schema);
    }

    public Element toXML(Context context)
    {
        Element element = new Element("required", "http://www.brics.dk/DSD/2.0");
        for(Iterator iterator = contents.iterator(); iterator.hasNext(); element.addContent(((AttributeDeclaration)iterator.next()).toXML(context)));
        return element;
    }

    void checkRequirements(Context context, Set set)
    {
        Iterator iterator = contents.iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            AttributeDeclaration attributedeclaration = (AttributeDeclaration)iterator.next();
            byte byte0 = attributedeclaration.evaluate(context);
            if(byte0 == 2)
                context.v.invalid(context, "required attribute missing in element " + Validator.getElementName(context.e), attributedeclaration.toXML(context));
            else
            if(byte0 == 3)
                context.v.invalid(context, "required attribute not always present in element " + Validator.getElementName(context.e) + " (attribute value might be illegal)", attributedeclaration.toXML(context));
            else
            if(byte0 == 4)
                context.v.invalid(context, "required attribute may be missing in element " + Validator.getElementName(context.e), attributedeclaration.toXML(context));
        } while(true);
    }

    void findDeclarations(List list)
    {
        list.addAll(contents);
    }

    void collectAttributeNormalization(Context context, Map map, Map map1, Map map2, Map map3)
    {
        for(Iterator iterator = contents.iterator(); iterator.hasNext(); ((Declaration)iterator.next()).collectAttributeNormalization(context, map, map1, map2, map3));
    }

    List contents;
}
